//
//  PodiumListeController.m
//  Kayak
//
//  Created by Lion User on 07/06/2012.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "PodiumListeController.h"

@interface PodiumListeController ()

@end

@implementation PodiumListeController
@synthesize tableView;
@synthesize liste;

-(id)init{
    self = [super init];
    liste = [[NSMutableArray alloc] init];
    return self;
}

-(void)AjoutParticipant:(Participant *) part
{
    NSSortDescriptor *sortDescriptor;
    sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"sortValue" ascending:YES] autorelease];
    NSArray * sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
//    Participant *p = [[Participant alloc] initWithData:part.nom :part.prenom :part.pays :part.numero];
//    Participant *p = [part copy];
    [liste addObject:part];
    liste = [[NSMutableArray alloc] initWithArray:[liste sortedArrayUsingDescriptors:sortDescriptors]];
    [tableView reloadData];
}

-(void)ReloadTableView
{
    [tableView reloadData];
}

-(NSMutableArray *) GetSortedList
{
    NSSortDescriptor *sortDescriptor;
    sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"sortValue" ascending:YES] autorelease];
    NSArray * sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
    //    Participant *p = [[Participant alloc] initWithData:part.nom :part.prenom :part.pays :part.numero];
    //    Participant *p = [part copy];
    return [[NSMutableArray alloc] initWithArray:[liste sortedArrayUsingDescriptors:sortDescriptors]];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if ([liste count] < 3)
    {
        return [liste count];
    }
    else
        return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero] autorelease];
    
    Participant *participant = [liste objectAtIndex:indexPath.row];
    
    
    NSString *label = [NSString stringWithFormat:@"%i - %@ %@ - %@ - %@", participant.numero,participant.prenom, participant.nom, participant.pays, participant.descente.recupererTempsCalculer];
    if(participant != nil){
        cell.textLabel.text = label;
	}else{
		cell.textLabel.text = @"PARTICPANT IS NULL";
	}
    
    return cell;
}

@end
